<template v-if="profile.token">
  <li>
    <a href="javascript:;"><i class="iconfont icon-user"></i>
      {{profile.account}}
    </a>
  </li>
  <li><a @click="logout()" href="javascript:;">退出登录</a></li>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
export default {
  name: 'AppTopnav',
  setup () {
    // 获取用户的登录信息才能控制切换导航菜单
    const store = useStore()
    // 使用vuex中的state需要设置计算属性，否则不是响应式
    const profile = computed(() => {
      return store.state.user.profile
    })
    const router = userRouter()
    const logout = () => {
      store.commit('user/setUser',{})
      router.push('/login')
    }
    return { profile, logout}
  }
}
</script>


<style scoped>

</style>